package controllers

import (
	"codehub-g.huawei.com/videocloud/mediaprocesscenter/application-gateway/pkg/apis"
	"codehub-g.huawei.com/videocloud/mediaprocesscenter/application-gateway/pkg/utils/clients"
	"codehub-g.huawei.com/videocloud/mediaprocesscenter/application-gateway/pkg/utils/errors"
	"codehub-g.huawei.com/videocloud/mediaprocesscenter/application-gateway/pkg/utils/log"
	"fmt"
	"github.com/beego/beego/v2/server/web"
	"net/http"
)

type GetConfigControllerImpl struct {
	web.Controller
}

// GetConfigController implements get fleetid sgid instanceid publicip privateip projectid
var GetConfigController = &GetConfigControllerImpl{}

// GetConfig get fleetid sgid instanceid publicip privateip projectid
func (a *GetConfigControllerImpl) GetConfig() {
	tLogger := log.GetTraceLogger(a.Ctx)

	hostname := a.GetString(":hostname")

	tLogger.Infof("[GetConfigController] received a get request for auxproxy %s", hostname)

	itc, err := clients.AASSClient.GetConfigByHostname(hostname)
	if err != nil {
		tLogger.Errorf("[configuration controller] failed to get config for %v", err)
		Response(a.Ctx, http.StatusInternalServerError, errors.NewGetInstanceConfigurationError(fmt.Sprintf(
			"can not get config for hostname %s for %v", hostname, err), http.StatusInternalServerError))
		return
	}

	res := apis.GetConfigResponse{GetConfig: *itc}
	Response(a.Ctx, http.StatusOK, res)
}
